Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
How to delete two "tr" rows with js?

When I delete product into basket, products deleted successfully but company name does not delete. I'm using javascript. i cant solve the problem, help me pls...

enter image description here

function getCurrentRow(t) {
  var v = parseInt($.trim(t.attr("data-row-id")));
  if (isNaN(v)) {
    console.log("data-row-id:null");
    return null;
  }
  var currentRow = getRow(v);
  if (currentRow == null) {
    console.log("currentRow:null");
    return null;
  }
  return currentRow;
}

// Delete
basketContainer.on('click', 'button[data-button-name="delete"]', function() {
  var o = $(this);

  var t = o.closest("tr");

  var currentRow = getCurrentRow(t);
  if (currentRow == null) {
    return;
  }
  postData(t, currentRow.index, {
    "basketid": currentRow.id,
    "pdoductid": currentRow.ProductID,
    "count": 0,
    "cmdtype": cmdTypes.Delete
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<table>
  <thead>
    <tr data-row-id="item.id">
      <td colspan="4" style="color: #d53434">Shop: <strong>Shop name</strong></td>
    </tr>
  </thead>

  <tbody>
    <tr role="row" data-row-id="item2.id">
      ...
    </tr>
  </tbody>
</table>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You mean remove the table when no more products from that shop?

$("#basketContainer").on('click', 'button[data-button-name="delete"]', function() {
  const $tr = $(this).closest("tr");
  const $tb = $(this).closest("tbody");
  $tr.remove()
  if ($tb.find("tr").length === 0) $tb.closest("table").remove()

});
table {
  border: 1px solid black
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="basketContainer">
  <table>
    <thead>
      <tr data-row-id="item.id">
        <td colspan="4" style="color: #d53434">Shop: <strong>Shop name 1</strong></td>
      </tr>
    </thead>

    <tbody>
      <tr role="row" data-row-id="item2.id">
        <td><button type="button" data-button-name="delete">Delete</button></td>
      </tr>
      <tr role="row" data-row-id="item2.id">
        <td><button type="button" data-button-name="delete">Delete</button></td>
      </tr>
    </tbody>
  </table>
  <table>
    <thead>
      <tr data-row-id="item.id">
        <td colspan="4" style="color: #d53434">Shop: <strong>Shop name 2</strong></td>
      </tr>
    </thead>

    <tbody>
      <tr role="row" data-row-id="item2.id">
        <td><button type="button" data-button-name="delete">Delete</button></td>
      </tr>
      <tr role="row" data-row-id="item2.id">
        <td><button type="button" data-button-name="delete">Delete</button></td>
      </tr>
    </tbody>
  </table>

</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda